<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>数据查看器</title>
</head>
<body>
<div><span>数据交换</span></div>
<div>
    <div>
        <span>请选择RDB数据源</span><span><select></select></span><span>分割partition数</span><span><input id="ldPartition"
                                                                                                  type="text"
                                                                                                  name="ldPartition"></text></span><span><button
            onclick="preivew()">查看
    </button></span><span><button onclick="save2Hive()">保存到Hive</button></span>
    </div>
    <div>
        <span>请输入Parquet文件路径</span><span><input id="ldFilePath" type="text" name="ldFilePath"></text></span><span>分割partition数</span><span><input
            id="ldPartition" type="text" name="ldPartition"></text></span><span><button onclick="preivew()">查看</button></span><span><button
            onclick="save2Hive()">保存到Hive
    </button></span>
    </div>
    <div>
        <span>请输入HBASE路径</span><span><input id="ldHbaseFilePath" type="text" name="ldHbaseFilePath"></text></span><span>分割partition数</span><span><input
            id="ldHbaseFilePartition" type="text"
            name="ldHbaseFilePartition"></text></span><span>输出路径</span><span><input id="hbOutputDir" type="text"
                                                                                    name="hbOutputDir"></text></span><span><button
            onclick="preivewCols()">选择列
    </button></span><span><button onclick="saveHB2Parquet()">保存为Parquet文件格式</button></span>
    </div>
    <div id="hbaseColInfos" style="display:none"></div>
</div>
<br>

<div><span>查看文件信息</span></div>
<div>
    <div>
        <span>请输入文件路径</span><span><input id="filePath" type="text"
                                         name="filePath"></text></span><span>分割partition数</span><span><input
            id="partition" type="text" name="partition"></text></span><span><button onclick="viewBlocks()">查看blocks
    </button></span><span><button onclick="viewShuffle()">查看Shuffle</button></span>
    </div>
    <div>
        <span>Dataframe名</span><span><input id="df" type="text" name="df1"></text></span><span>合并partition数</span><span><input
            id="colPartition" type="text" name="colPartition"></text></span><span><button onclick="coalesce()">合并
    </button></span>
    </div>
</div>
</div>
<br>

<div><span>选择数据集合</span></div>
<div>
    <div>
        <span>df1</span><span><input id="df1" type="text" name="df1"></text></span><span>key1</span><span><input
            id="key1" type="text" name="key1"></text></span><span><button>查看blocks</button></span>
    </div>
    <div>
        <span>df2</span><span><input id="df2" type="text" name="df2"></text></span><span>key2</span><span><input
            id="key2" type="text" name="key2"></text></span>
    </div>
    <div>
        <span>groupKey</span><span><input id="groupKey" type="text" name="groupKey"></text></span>
    </div>
    <div><span><select id="dataType" name="dataType">
        <option value="0">hive</option>
        <option value="1">parquet</option>
    </select></span><span><button onclick="runjoin()">join</button></span></div>
</div>
<br>

<div><span>自定义sql</span></div>
<div>
    <div>
        <span><textarea id="sql" cols="50" rows="10"></textarea></span><span>
    </div>
    <div><span><button onclick="runjoin()">sql执行</button></span></div>
</div>
<div>
    <span id="output" class="output"></span>
</div>
</body>
<style>
    div {
        margin-top: 5px;
    }

    span {
        margin-left: 5px;
    }

    span .output {
        color: red;
    }
</style>
<script type="text/javascript" src="js/jquery/jquery-1.9.1.min.js"></script>
<script language="javascript">
    function runjoin() {
        var df1 = document.getElementById("df1").value;
        var df2 = document.getElementById("df2").value;
        var key1 = document.getElementById("key1").value;
        var key2 = document.getElementById("key2").value;
        var groupKey = document.getElementById("groupKey").value;
        var dataType = document.getElementById("dataType").value;
        var url = "./op/join";
        var para = "df1=" + df1 + "&df2=" + df2 + "&key1=" + key1 + "&key2=" + key2 + "&groupKey=" + groupKey + "&dataType=" + dataType;
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                $("#output").html("<font color='red'>" + data + "</font>");
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }

    function runSql() {
        var sql = document.getElementById("sql").value;
        var para = "sql=" + sql;
        var url = "./op/execSql";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                $("#output").html(data);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }
    function viewBlocks() {
        var filePath = document.getElementById("filePath").value;
        var partition = document.getElementById("partition").value;
        var para = "filePath=" + filePath + "&partition=" + partition;
        var url = "./op/viewBlocks";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                for (key in data) {
                    html = html + key + "=>" + "countBlocks:" + data[key].countBlocks + ", totalSize:" + data[key].totalSize
                    html = html + "<br>"
                }
                $("#output").html(html);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }
    function viewShuffle() {
        var filePath = document.getElementById("filePath").value;
        var partition = document.getElementById("partition").value;
        var para = "filePath=" + filePath + "&partition=" + partition;
        var url = "./op/viewShuffle";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                $("#output").html(data);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }

    function coalesce() {
        var df = document.getElementById("df").value;
        var partition = document.getElementById("colPartition").value;
        var para = "df=" + df + "&partition=" + partition;
        var url = "./op/coalesce";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                $("#output").html(data);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }

    function save2Hive() {
        var filePath = document.getElementById("ldFilePath").value;
        var partition = document.getElementById("ldPartition").value;
        var para = "filePath=" + filePath + "&partition=" + partition;
        var url = "./ld/ld2h";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                $("#output").html(data);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }

    function saveHB2Parquet() {
        var filePath = document.getElementById("ldHbaseFilePath").value;
        var partition = document.getElementById("ldHbaseFilePartition").value;
        var outputdir = document.getElementById("hbOutputDir").value;
        var para = "filePath=" + filePath + "&partition=" + partition + "&targetDir=" + outputdir;
        var url = "./ld/ldhb2h";
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                $("#output").html(data);
            },
            error: function (data) {
                $("#output").html(data);
            }
        })
    }

    function preivewCols() {
        var filePath = document.getElementById("ldHbaseFilePath").value;
        var para = "filePath=" + filePath;
        var url = "./ld/prevHbCols";
        $("#hbaseColInfos").html("");
        $("#hbaseColInfos").hide();
        $.ajax({
            type: "POST",
            async: true,
            data: para,
            url: url,
            success: function (data) {
                var html = "";
                var data = data.responseText;
                var cols = data.split(" ");
                for (var i = 0; i < cols.length; i++) {
                    html += '<input type="checkbox" name="hbCols" value="' + cols[i] + '">' + '<font size="10">' + cols[i] + '</font>';
                }
                $("#hbaseColInfos").html(html);
                $("#hbaseColInfos").show();
            },
            error: function (data) {
                var html = "";
                var data = data.responseText;
                var cols = data.split(" ");
                for (var i = 0; i < cols.length; i++) {
                    html += '<input type="checkbox" name="hbCols" value="' + cols[i] + '">' + '<font size="1">' + cols[i] + '</font>';
                }
                $("#hbaseColInfos").html(html);
                $("#hbaseColInfos").show();
            }
        })
    }
</script>
</html>
